Home

Computer science

'

1. Classes and objects - Billing

Create a cash register for a fruit store that enables to complete purchases (applying offers, if any), etc.

Project Setup

Class:\r\nRegister: Singleton class

  • Maintains a list of items for sale and their prices.
  • Initiates and completes a checkout by returning a total bill amount.

Methods:

  • Register getInstance() - static method
  • String getTotalBill(Map<String, Integer> itemDetails)

Function Description

  1. Create the function getInstance in the Register class. Return the singleton instance of a Register class using the register variable which was declared and initiated to null.
  2. Complete the function getTotalBill in the editor below. The function must state what must be returned.

getTotalBill has the following parameter(s):

  • itemDetails: a key/value pair of string key and integer value

The register contains the list of items and their prices. In this exercise, the list of items and their prices are:

Item


'

Answer